<fieldset id="fd1" style="width:95%;margin:5px;">
	<legend><span>工单信息查询</span></legend>
	<div class="fieldset-body">
		<table class="form-table" border="0" cellpadding="1" cellspacing="2">
			<tr>
				<td class="form-label" style="width:100px;">施工组织机构:</td>
				<td style="width:150px"><input id="conagency" expandOnLoad="true" class="mini-treeselect" url="/common/agencyOne" multiSelect="false" textField="name" valueField="id" parentField="parent" checkRecursive="true" showFolderCheckBox="true" style="width:100%;"/></td>
				<td class="form-label" style="width:80px;">工单类型:</td>
				<td style="width:100px"><input id="types" class="mini-combobox" textField="name" valueField="id" data="JS.CONST[5]" allowInput="true" style="width:100%;" /></td>
				<td class="form-label" style="width:80px;">工单编号:</td>
				<td style="width:100px"><input id="order_no" class="mini-textbox" emptyText="请输入工单编号" style="width:100%;"/></td>
				<td class="form-label" style="width:80px;">售后单编号:</td>
				<td style="width:100px"><input id="order_id" class="mini-textbox" emptyText="请输入售后单编号" style="width:100%;"/></td>
				<td style="width:80px;"><a class="mini-button" id="search" iconCls="icon-search">查询...</a></td>
			</tr>
		</table>
	</div>
</fieldset>
<div class="mini-toolbar" style="padding:0px;margin:6px 0px 0px 0px;border-bottom:0;width:100%;">
	<table style="width:100%;">
		<tr>
			<td style="width:100%;">
				<a class="mini-button" iconCls="icon-node" id="btnVerify" onClick="review()" plain="true">审核处理</a>
				<span class="separator"></span>
				<a class="mini-button" iconCls="icon-search" onClick="BusinessInfo('id')" plain="true">查看工单详情</a>
				<a class="mini-button" iconCls="icon-search" onClick="CustomerInfo('customer_id')" plain="true">查看顾客详情</a>
				<span class="separator"></span>
				<font color="red">*审核顺序从下级机构到总部分步审核</font>
			</td>
		</tr>
	</table>
</div>
<table style="width:100%;height:70%;">
	<tr>
		<td style="width:100%;height:100%;">
			<div id="grid1" class="mini-datagrid" allowAlternating="true" idField="id" pageSize="20" onselectionchanged="onSelectionChanged" style="width:100%;height:100%;" url="/business/dispatchingReview" >
				<div property="columns">
					<div type="indexcolumn" headerAlign="center">编号</div>
					<div field="id" width="60" headerAlign="center" Align="center" allowSort="true">工单编号</div>
					<div field="typename" width="80" headerAlign="center" allowSort="true" align="center">工单类型</div>
					<div field="statusname" width="100" headerAlign="center" Align="center" allowSort="true">状态</div>
					<div field="title" width="80">标题</div>
					<div field="content" width="200" headerAlign="center">工单内容</div>
					<div field="remark" width="200" headerAlign="center">备注<input property="editor" class="mini-textarea" emptyText="请输入备注" style="width:100%;height:40px;"/></div>
				</div>
			</div>
		</td>
		<td style="width:650px;height:100%;">
			<div id="grid2" class="mini-datagrid" showFooter="false" allowAlternating="true" idField="id" pageSize="20" onselectionchanged="onSelectionChangedTwo" style="width:450px;height:100%;" url="/business/okList" >
				<div property="columns">
					<div type="checkcolumn" headerAlign="center">选择</div>
					<div field="agencyname" width="120">审核机构</div>
					<div field="staff" width="120">审核人</div>
					<div field="status" width="50" headerAlign="center" Align="center">状态</div>
					<div field="remark" width="280" headerAlign="center">备注</div>
					<div field="updated" width="150" headerAlign="center" dateFormat="yyyy-MM-dd HH:mm:ss">审核时间</div>
				</div>
			</div>
		</td>
	</tr>
</table>
<script type="text/javascript">
mini.parse();
var urlDel = "/customer/customerDel";
var urlUpd = "/customer/customerUpd";
mini.get("btnVerify").disable();
var grid = mini.get("grid1");
grid.load({statuss:8});
var grid2 = mini.get("grid2");
grid2.load();

//设置行样式
grid2.on("drawcell", function (e) {
	var bgcolor="limegreen";
	if(e.record.status=="未审核"){
		bgcolor="orangered";
	}
	if(e.record.status=="未通过"){
		bgcolor="red";
	}
	e.cellStyle = "background:" + bgcolor;
});

//选择订单
function onSelectionChanged(e){
	var gridSelection = e.sender;
	var record = gridSelection.getSelected();
	if (record) {
		grid2.load({id:record.id});
	}
}

//选择订单
function onSelectionChangedTwo(e){
	var gridSelection = e.sender;
	var record = gridSelection.getSelected();
	if (record) {
		var flg = true;
		//判断下级机构是否通过
		grid2.findRows(function(row){
		    if(row.id > record.id){
			    if(row.status != "通过"){
			    	flg = false;
		    		return false;
			    }
		    }
		});

		//判断是否审核过
		if(flg){
			var staff = "," + record.staff_id + ",";
			if(flg && staff.indexOf("," + JS.id + ",") >= 0 &&　record.status=="未审核"){
				mini.get("btnVerify").enable();
			}else{
				mini.get("btnVerify").disable();
			}
		}
	}
}

//查询
$("#search").click(function(){
	grid.load({
		id:mini.get("order_no").getValue(),
		order_id:mini.get("order_id").getValue(),
		statuss:8,
		types:mini.get("types").getValue(),
		con_agency_id:mini.get("conagency").getValue()
	});
});

//派工到下属组织机构
function review(){
	var row = grid2.getSelected();
	if (row != null) {
		mini.open({
            url: "/business/review",
            title: "完工审核", width: 480, height:250,
            onload: function()
            {
                var iframe = this.getIFrameEl();
                var data = { action: "edit",id:row.id};
                iframe.contentWindow.SetData(data);
            },
            ondestroy:function(action)
            {
				grid.load({
					id:mini.get("order_no").getValue(),
					order_id:mini.get("order_id").getValue(),
					statuss:8,
					types:mini.get("types").getValue(),
					con_agency_id:mini.get("conagency").getValue()
				});
            }
        });
		$(".mini-panel-border .mini-panel-body iframe").css("height","95%");
	} else {
		parent.$.dooDialog.alert("请选中一条记录");
	}
}
</script>